Tutorial B: More Single Qubit Gates
Contents
Tutorial B: More Single Qubit Gates¶
In this short tutorial, we’ll cover more quantum gates.
Objectives:¶
to apply the two other Pauli Gates.
to apply gates with parameters and other phase gates.
Importing Modules
import qiskit
from qiskit import *
from qiskit.visualization import *
In Tutorial A, we covered only two: the X gate and the Hadamard gate. There are more quantum gates to explore, so let’s go through a few ones now.
1. Pauli Gates¶
The X gate is grouped with two other gates, namely the Y gate and the Z gate. Together with the Identity operator, these are called Pauli gates. We will test these out now.
ycircuit=QuantumCircuit(1)
ycircuit.y(0)
ycircuit.draw(output='mpl')
Above, we’ve created a quantum circuit with a Y gate. Let’s visualize what happens.
visualize_transition(ycircuit, trace=True, saveas=None, fpg=50, spg=2)
Let’s compare to the X gate that we had before.
xcircuit=QuantumCircuit(1)
xcircuit.x(0)
visualize_transition(xcircuit,trace=True, saveas=None, fpg=50, spg=2)
Well, we see that the qubit state goes from \(|0\rangle\) to \(|1\rangle\) when both gates are applied. There’s just one difference… The trace the vector makes in the transition.
Let’s verify this by applying each gate twice.
xcircuit=QuantumCircuit(1)
xcircuit.x(0)
xcircuit.x(0)
visualize_transition(xcircuit,trace=True, saveas=None, fpg=50, spg=2)
ycircuit=QuantumCircuit(1)
ycircuit.y(0)
ycircuit.y(0)
visualize_transition(ycircuit,trace=True, saveas=None, fpg=50, spg=2)
You may have noticed that the X gate causes a rotation about the x axis, whilst the Y gate causes a rotation about the z axis.
Let’s examine the Z gate now.
zcircuit=QuantumCircuit(1)
zcircuit.z(0)
zcircuit.draw(output='mpl')
visualize_transition(zcircuit, trace=True, saveas=None, fpg=50, spg=2)
You’ll notice no transition as the measurement axis for the qubit states \(|0\rangle\) and \(|1\rangle\) are on the z axis. A rotation about the z axis would mean that the vector is spinning on itself.
To visualize a transition with the Z gate, we’ll place the qubit state at an angle. We’ll use the Hadamard to place the qubit in superposition, then apply the Z gate.
zcircuit=QuantumCircuit(1)
zcircuit.h(0)
zcircuit.z(0)
zcircuit.draw(output='mpl')
visualize_transition(zcircuit, trace=True, saveas=None, fpg=50, spg=2)
The light blue trace represents the z axis rotation.
Great! We’ve seen two more gates.
Quiz¶
Can you think of a sequence of two gates that will allow the qubit to end up in the same state as above?
Test it out in the space below then click to reveal the answer.
test_circuit=QuantumCircuit(1)
# Write your code here to add two of the four gates that we've learnt to the quantum circuit #
# visualize_transition(test_circuit, trace=True, saveas=None, fpg=50, spg=2) #Remove the first '#' on this line
Answer: Apply first the X gate followed by the Hadamard gate to get the \(|0\rangle -|1\rangle\) state.
2. Other Gates¶
Use the space below to test the following gates: the S gate with s() and T gate with t().
Hint:
Try applying a certain gate before to be able to visualize a transition for the s and t gates.
scircuit=QuantumCircuit(1)
# Write code to visualize the S gate transition #
#visualize_transition(scircuit, trace=True, saveas=None, fpg=50, spg=2) #Remove the first '#' on this line
tcircuit=QuantumCircuit(1)
# Write code to visualize the S gate transition #
#visualize_transition(tcircuit, trace=True, saveas=None, fpg=50, spg=2) #Remove the first '#' on this line
What you should see:
After placing the qubit in equal superposition you shall see that the S gate causes a 90\(^\circ\) rotation about the z axis, whilst the T gate causes a 45\(^\circ\) rotation about the z axis.